﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using DAOService;
using DTOService;

namespace BUSService
{
    public class MyService : IMyService
    {
        #region Khai báo thuộc tính
        private ServiceHost MyServiceHost { get; set; }
        private IMyService IMyServiceHost { get; set; }

        private DAOBangDia DaoBD = new DAOBangDia();
        private DAOBangDia_MatHuHong DaoBDMat = new DAOBangDia_MatHuHong();
        private DAOBangDia_Muon DaoBDMuon = new DAOBangDia_Muon();
        private DAOKhachHang DaoKH = new DAOKhachHang();
        private DAOLoaiBangDia DaoLBD = new DAOLoaiBangDia();
        private DAOLoaiSanPham DaoLSP = new DAOLoaiSanPham();
        private DAOQuyDinh DaoQD = new DAOQuyDinh();
        private DAOTinhTrang DaoTT = new DAOTinhTrang();
        
        #endregion
 
        public bool ConnectToService()
        {
            //try
            //{
            //    WSHttpBinding ws = new WSHttpBinding();
            //    ws.Security.Mode = SecurityMode.Message;
            //    ws.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            //    EndpointAddress ep = new EndpointAddress("http://localhost:8732/Design_Time_Addresses/BUSService/MyService/");
            //    ChannelFactory<IMyService> cf = new ChannelFactory<IMyService>(ws, ep);
            //    this.IMyServiceHost = cf.CreateChannel();
            //    return true;
            //}
            //catch
            //{
            //    return false;
            //}
            return true;
        }

        #region TinhTrang
        public DTOService.TinhTrang[] SelectTinhTrang()
        {            
            return DaoTT.SelectTinhTrang();
        }
        public DTOService.TinhTrang GetTinhTrang(int ma)
        {
            return DaoTT.GetTinhTrang(ma);
        }
        public int InsertTinhTrang(TinhTrang parr)
        {
            return DaoTT.InsertTinhTrang(parr);
        }
        public int UpdateTinhTrang(TinhTrang parr)
        {
            return DaoTT.UpdateTinhTrang(parr);
        }
        public int DeleteTinhTrang(TinhTrang parr)
        {
            return DaoTT.DeleteTinhTrang(parr);
        }
        #endregion

        #region LoaiSanPham
        public DTOService.LoaiSanPham[] SelectLoaiSanPham()
        {
            return DaoLSP.SelectLoaiSanPham();
        }
        public int InsertLoaiSanPham(LoaiSanPham parr)
        {
            return DaoLSP.InsertLoaiSanPham(parr);
        }
        public int UpdateLoaiSanPham(LoaiSanPham parr)
        {
            return DaoLSP.UpdateLoaiSanPham(parr);
        }
        public int DeleteLoaiSanPham(LoaiSanPham parr)
        {
            return DaoLSP.DeleteLoaiSanPham(parr);
        }
        public LoaiSanPham GetLoaiSanPham(int id)
        {
            return DaoLSP.GetLoaiSanPham(id);
        }
        #endregion

        #region LoaiBangDia
        public DTOService.LoaiBangDia[] SelectLoaiBangDia()
        {
            return DaoLBD.SelectLoaiBangDia();
        }
        public DTOService.LoaiBangDia GetLoaiBangDia(int ma)
        {
            return DaoLBD.GetLoaiBangDia(ma);
        }
        public int InsertLoaiBangDia(LoaiBangDia parr)
        {
            return DaoLBD.InsertLoaiBangDia(parr);
        }
        public int UpdateLoaiBangDia(LoaiBangDia parr)
        {
            return DaoLBD.UpdateLoaiBangDia(parr);
        }
        public int DeleteLoaiBangDia(LoaiBangDia parr)
        {
            return DaoLBD.DeleteLoaiBangDia(parr);
        }
        #endregion

        #region KhachHang
        public KhachHang[] SelectKhachHang()
        { 
            return DaoKH.SelectKhachHang(); 
        }
        public KhachHang GetKhachHang(string ma)
        {
            return DaoKH.GetKhachHang(ma);
        }
        public KhachHang[] SearchKhachHang(string ten)
        {
            return DaoKH.SearchKhachHang(ten);
        }
        public string DeleteKhachHang(KhachHang parr)
        {
            return DaoKH.DeleteKhachHang(parr);
        }
        public string InsertKhachHang(KhachHang parr)
        {
            return DaoKH.InsertKhachHang(parr);
        }
        public string UpdateKhachHang(KhachHang parr)
        {
            return DaoKH.UpdateKhachHang(parr);
        }
        
        public KhachHang[] SelectKhachHang(int startIndex,int numRows)
        {
            return DaoKH.SelectKhachHang(startIndex, numRows);
        }
        public KhachHang[] SelectKhachHangTheoTen_Limit(string name,int startIndex, int numRows)
        {
            return DaoKH.SelectKhachHangTheoTen_Limit(name,startIndex, numRows);
        }
        public KhachHang[] SelectKhachHangTheoTen(string name)
        {
            return DaoKH.SelectKhachHangTheoTen(name);
        }
        public int NumberOfKhachHang()
        {
            return DaoKH.NumberOfKhachHang();
        }
        public int NumberOfKhachHang(string name)
        {
            return DaoKH.NumberOfKhachHang(name);
        }
        public int SoBangDiaKhachHangDangThue(KhachHang parr)
        {
            return DaoKH.SoBangDiaKhachHangDangThue(parr);
        }
        #endregion

        #region BangDia
        public DTOService.BangDia[] SelectBangDia()
        {
            return DaoBD.SelectBangDia();
        }
        public DTOService.BangDia[] SelectBangDia(string name)
        {
            return DaoBD.SelectBangDia(name);
        }
        public int UpdateBangDia(BangDia bd)
        {
            return DaoBD.UpdateBangDia(bd);
        }

        public int DeleteBangDia(String mabd)
        {
            return DaoBD.DeleteBangDia(mabd);
        }

        public bool InsertBangDia(BangDia bd)
        {
            return DaoBD.InsertBangDia(bd);
        }

        public string SetMaBangDia()
        {
            return DaoBD.SetMaBangDia();
        }

        public BangDia GetBangDia(string ma)
        { return DaoBD.GetBangDia(ma); }

        public int GhiNhanTinhTrang(string ma, int flag)
        {
            return DaoBD.GhiNhanTinhTrang(ma, flag);
        }

        public BangDia[] TimKiemBangDia(BangDia bd, int pagesize, int skip)
        {
            return DaoBD.TimKiemBangDia(bd, pagesize, skip);
        }

        public int NumberBangDia()
        {
            return DaoBD.NumberBangDia();
        }

        public int NumberBangDia(BangDia bd)
        {
            return DaoBD.NumberBangDia(bd);
        }

        public BangDia[] SelectBangDia_Limit(int pagesize, int skip)
        {
            return DaoBD.SelectBangDia_Limit(pagesize, skip);
        }

        public BangDia[] SelectBangDiaThueNhieuNhat()
        {
            return DaoBD.SelectBangDiaThueNhieuNhat();
        }
        public BangDia[] ThongKeBangDiaThueNhieu(int thang, int nam)
        {
            return DaoBD.ThongKeBangDiaThueNhieu(thang, nam);
        }
        #endregion

        #region QuyDinh
        public QuyDinh SelectQuyDinh()
        {
            return DaoQD.SelectQuyDinh();
        }
        public int UpdateQuyDinh(QuyDinh parr)
        {
            return DaoQD.UpdateQuyDinh(parr);
        }
        #endregion

        #region BangDia_Muon
        public BangDia_Muon[] BaoCaoThang_Nam(int thang, int nam)
        {
            return DaoBDMuon.BaoCaoThang_Nam(thang, nam);
        }
        public float TongDoanhThuThang(int thang)
        {
            return DaoBDMuon.TongDoanhThuThang(thang);
        }
        public BangDia_Muon[] ThongKeBangDiaQuanHan()
        {
            return DaoBDMuon.ThongKeBangDiaQuanHan();
        }
        
        public BangDia_Muon[] GetBangDia_MuonOFKhachhang(string makh)
        {
            return DaoBDMuon.GetBangDia_MuonOFKhachhang(makh);
        }
        public BangDia_Muon GetBangDia_Muon(string mabd, string makh)
        {
            return DaoBDMuon.GetBangDia_Muon(mabd, makh);
        }
        public int TraDia(BangDia_Muon bdm)
        {
            return DaoBDMuon.TraDia(bdm);
        }
        public string ChoThueBangDia(BangDia_Muon parr)
        {
            return DaoBDMuon.InsertBangDia_Muon(parr);
        }
        #endregion

        #region BangDia_MatHuHong

        #endregion
    }
}
